﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Week1.world.behavior
{

    #region TriggerKey
    /// <summary>
    /// Class containing trigger condition that is passed to behavior class.
    /// </summary>
    public class TriggerKey
    {
        /// <summary>
        /// Trigger types
        /// </summary>
        public enum TriggetType
        {
            Location, Movement, ShotAt, Shooting, Taling, Animating, Collision, GameUpdate, GameTimeSec, Keyboard
        }


        public TriggetType oTriggetType;

        /// <summary>
        /// value for location based trigger
        /// </summary>
        public Vector3 oLocation;

        /// <summary>
        /// start time for time based trigger
        /// </summary>
        public long lSecStartTime;
        /// <summary>
        /// end time for time based trigger
        /// </summary>
        public long lSecEndTime;

        /// <summary>
        /// Keyboard key for keyboard based trigger
        /// </summary>
        public Keys Key = Keys.A;

        public TriggerKey():base()
        {
        }

    }
    #endregion

    #region TriggerManager
    /// <summary>
    /// Trigger Manager class that must be registered as a game component to work. It will keep certain triggers up to date, such as keystate
    /// and other regularly updated events that can be used as trigger. Register in Game class to make it work.
    /// </summary>
    public class TriggerManager : Microsoft.Xna.Framework.DrawableGameComponent
    {

        private static TriggerManager instance;
        public GameTime oGameTime;
        public Keys[] oKeyState;

        private TriggerManager(Game oGame)
            : base(oGame)
        {
        }

        /// <summary>
        /// returns a singleton instance. Must be called from game class
        /// </summary>
        /// <param name="oGame"></param>
        /// <returns></returns>
        public static TriggerManager getInstance(Game oGame)
        {
                if (instance == null)
                {
                    instance = new TriggerManager(oGame);
                }
                return instance;            
        }

        /// <summary>
        /// Can only be called after getInstance(game) is called first from main game class.
        /// Returns a singleton instance.
        /// </summary>
        /// <returns></returns>
        public static TriggerManager getInstance()
        {
            return instance;
        }

        public override void Update(GameTime gameTime)
        {
            oKeyState = Keyboard.GetState().GetPressedKeys();
            oGameTime = gameTime;
            base.Update(gameTime);
        }
    }
    #endregion 
}
